package com.mc.search;


//判断是否是一个树的子树
public class JudgeSub {
	
	public static boolean isSub(Node tar, Node sub){
		
		boolean res = false;
		if(tar!=null&&sub!=null){
			if(tar.value==sub.value)
				res = judge(tar,sub);
			if(!res)
				res = isSub(tar.left, sub);
			if(!res)
				res = isSub(tar.right, sub);
		}
		return res;
		
	}
	public static boolean judge(Node tar, Node sub){
		if(sub==null)
			return true;
		
		if(tar==null)
			return false;

		if(tar.value!=sub.value)
			return false;
		
		return judge(tar.left,sub.left)&&judge(tar.right,sub.right);
	}
	static class Node{
		Node left;
		Node right;
		int value;
		public Node(int value){
			this.value = value;
		}
	}
}
